/**
 * Copyright (c) 2002-2012 旭鸣信息
 * All rights reserved. 
 * File：WebCounterFilterProxy.java
 * History: Nov 18, 2013: Initially created, liuzhi.
 */
package com.xteam.ecsystem.utils;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * 网站浏览量统计过滤器的代理类
 * @author liuzhi
 *
 */
public class WebCounterFilterProxy implements Filter {

	private String targetFilterBean;
	
	private Filter proxyFilter;
	
	@Override
	public void destroy() {
		System.out.println("=============== WebCounterFilterProxy destroy ============");
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		proxyFilter.doFilter(req, resp, chain);
	}

	@Override
	public void init(FilterConfig config) throws ServletException {
		System.out.println("=============== WebCounterFilterProxy init ============");
		
		this.targetFilterBean = config.getInitParameter("targetFilterBean");
		ServletContext sc = config.getServletContext();
		WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(sc);
		this.proxyFilter = (Filter)wac.getBean(this.targetFilterBean);
		this.proxyFilter.init(config);

	}

}
















